home *** CD-ROM | disk | FTP | other *** search
- /* XGApplication.h
- *
- * This is the application class object; this is the thing which
- * handles setting up the main event loop.
- */
-
- /* YAAF - Yet another application framework
- * Copyright (C) 1997 William Edward Woody and In Phase Consulting
- *
- * This library is free software; you can redistribute it
- * and/or modify it under the terms of the GNU Library
- * General Public License as published by the Free Software
- * Foundation; either version 2 of the License, or any
- * later version.
- *
- * This library is distributed in the hope that it will be
- * useful, but WITHOUT ANY WARRANTY; without even the implied
- * warranty of MERCHANTABIILITY or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU Library General Public License for
- * more details.
- *
- * You should have received a copy of the GNU Library General
- * Public License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- *
- * To contact the author, either e-mail me at
- * woody@alumni.caltech.edu, or write to us at
- *
- * William Edward Woody
- * In Phase Consulting
- * 1545 Ard Eevin Avenue
- * Glendale, CA 91202
- */
-
- #ifndef __XAPPLICATION_H__
- #define __XAPPLICATION_H__
-
- #include <XConfig.h>
- #include <XEvent.h>
-
- #if defined(__MWERKS__)
- #if defined(macintosh)
- #pragma options align=power
- #endif
- #if defined(__INTEL__)
- #pragma pack(push,2)
- #endif
- #endif
-
- /************************************************************************/
- /* */
- /* Forwards */
- /* */
- /************************************************************************/
-
- class XGView;
- class XGWindow;
- class XGMenuBar;
-
- /************************************************************************/
- /* */
- /* Class Declarations */
- /* */
- /************************************************************************/
-
- /* XGAppCore
- *
- * This is the low level application core. This contains the
- * code for handling the generic event loop.
- *
- * This is an abstract class--we generate the events here, but
- * we don't know where we send those events. That's left for the
- * children, who maintain and manage the various configurations.
- */
-
- class XGAppCore : public XGDispatch, public XGFocus {
- public:
- /*
- * Construction/Destruction
- */
-
- XGAppCore();
- virtual ~XGAppCore();
-
- /*
- * Event callbacks
- */
-
- #if OPT_MACOS == 1
- virtual long Open(FSSpec *);
- virtual long Print(FSSpec *);
- virtual long New(void);
- virtual long Quit(void);
-
- virtual bool FilterEvent(EventRecord *);
-
- void _DoActive(WindowPtr w, short flag);
- #endif
-
- #if OPT_WINOS == 1
- virtual void CommandLine(short argc, char **argv);
- virtual long Quit(void);
-
- virtual bool FilterEvent(MSG *);
- #endif
-
- /*
- * Event loop processing
- */
-
- virtual void Run(void); // Run event loop
- virtual bool _RunOnce(XGWindow *);
- virtual void Exit(void); // Do the 'quit' command
-
- /*
- * Root event processing
- */
-
- virtual void ShowCopyright(void);
- long ReceiveDispatch(long,long,void *);
-
- /*
- * Current focus support
- */
-
- virtual XGMenuBar *_GetCurMenu() = 0;
- virtual XGFocus *_GetCurFocus() = 0;
-
- /*
- * Modal support
- */
-
- bool IsModalWindow()
- {
- return (_fModalWindow) ? true : false;
- }
- private:
- bool fQuitFlag; // Quit?
- XGWindow *_fModalWindow; // Modal window?
-
- #if OPT_MACOS == 1
- /*
- * Internal Support
- */
-
- void InvalidateCornerIcon(WindowPtr);
- void DrawCornerIcon(WindowPtr);
-
- /*
- * Drag/drop support
- */
-
- static void InitOS6Finder(void);
- static OSErr GotRequiredParams(AppleEvent *);
- static pascal OSErr AEHandleProc(AppleEvent *, AppleEvent *, long);
-
- /*
- * Event loop dispatch
- */
-
- void DoEvent(EventRecord *);
-
- /*
- * Mouse event processing
- */
-
- void DoMouse(EventRecord *);
- void DoMouseDown(WindowPtr, Point, short);
- void DoMouseMove(EventRecord *);
-
- void DoUpdate(EventRecord *);
- void DoKeyDown(EventRecord *);
- void DoOSEvent(EventRecord *);
-
- void DoMenu(long);
-
- bool DoClose(WindowPtr);
-
- /*
- * Internal stuff
- */
-
- bool fFront;
-
- Point fLastClickPos;
- long fLastClickTime;
- #endif
-
- #if OPT_WINOS == 1
- void UpdateFocus();
- void CallCommandLine();
- #endif
- };
-
- /************************************************************************/
- /* */
- /* Single Window Application Type */
- /* */
- /************************************************************************/
-
- /* XGAppSingleWindow
- *
- * This implements a single-window application. On Windows, this
- * creates an SDI window application; on the Macintosh this creates
- * an application which quits as soon as the window is closed.
- *
- * The way this works is to create a single menu bar object
- * (in Windows, in the opened window), and update the menu bar
- * according to the messages received by 'ReceiveDispatch' (on the
- * periodic events).
- *
- * When the main window close event is received, we terminate
- * the event loop and quit this program.
- */
-
- class XGAppSingleWindow : public XGAppCore, public XGBroadcast {
- public:
- XGAppSingleWindow();
- virtual ~XGAppSingleWindow();
-
- /*
- * Application initialization procedures
- */
-
- void Run(void);
- void ReceiveBroadcast(long,long,void *);
- long ReceiveDispatch(long,long,void *);
-
- /*
- * Overrides--this determines how we handle the focus
- */
-
- virtual XGMenuBar *_GetCurMenu();
- virtual XGFocus *_GetCurFocus();
-
- private:
- XGWindow *fMyWindow;
- XGMenuBar *fMyMenuBar;
-
- /*
- * Initialization
- */
-
- #if OPT_WINOS == 1
- void _InitInstance();
- void _InitApplication();
- #endif
- };
-
- /************************************************************************/
- /* */
- /* Multiple Window Application Type */
- /* */
- /************************************************************************/
-
- /* WListRecord
- *
- * This is an internal record used to record the list of windows that
- * are in my application
- */
-
- struct _WLstRecord {
- short menuAccel;
- short menuID;
- XGMenuBar *fMenuBar;
- XGWindow *fWindow;
- };
-
- /* XGAppMultiWindow
- *
- * This implements a multi-window application. On Windows, this
- * creates an MDI window application; on the Macintosh this creates
- * the standard multi-window application
- *
- * This works by creating a global menu bar, and maintaining both
- * that menu bar and a global table of all the open windows. (This
- * is used to maintain the window menu.)
- *
- * We terminate only when we receive the standard quit command.
- */
-
- class XGAppMultiWindow : public XGAppCore, public XGBroadcast {
- public:
- XGAppMultiWindow(char *appName = NULL);
- virtual ~XGAppMultiWindow();
-
- /*
- * Application initialization procedures
- */
-
- void ReceiveBroadcast(long,long,void *);
- long ReceiveDispatch(long,long,void *);
-
- /*
- * Overrides--this determines how we handle the focus
- */
-
- virtual XGMenuBar *_GetCurMenu();
- virtual XGFocus *_GetCurFocus();
-
- private:
- /*
- * Initialization
- */
-
- #if OPT_WINOS == 1
- void _InitInstance(char *);
- void _InitApplication();
- #endif
-
- /*
- * Support routines
- */
-
- void _CreateWindow(XGWindow *);
- void _DestroyWindow(XGWindow *);
- void _RenameWindow(XGWindow *);
-
- void _SortWindowList();
- void _UpdateWindowMenu();
-
- void _TileWindows();
- void _CascadeWindows();
-
- #if OPT_WINOS
- void _ArrangeIcons();
- #endif
-
- /*
- * Internal structures
- */
-
- XGDynArray<_WLstRecord> fWindowList;
- XGMenuBar *fMyMenuBar;
- };
-
-
- /************************************************************************/
- /* */
- /* Startup Procedure */
- /* */
- /************************************************************************/
-
- /* StartApplication
- *
- * This is the very first thing that gets called when an application
- * is started up. This expects you to return an XGAppCore descendant
- * and do initialization specific to the particular application type.
- */
-
- extern XGAppCore *StartApplication(void);
-
- /************************************************************************/
- /* */
- /* Application Globals */
- /* */
- /************************************************************************/
-
- extern XGAppCore *_GApp;
-
- /************************************************************************/
- /* */
- /* Windows specific madness */
- /* */
- /************************************************************************/
-
- #if OPT_WINOS == 1
-
- extern char _GMainClass[];
- extern char _GWindowClass[];
- extern char _GViewClass[];
- extern char _GDlogClass[];
-
- extern LRESULT CALLBACK _GMainMDIWindowProc(HWND,UINT,WPARAM,LPARAM);
- extern LRESULT CALLBACK _GChildWindowProc(HWND,UINT,WPARAM,LPARAM);
- extern LRESULT CALLBACK _GSingleWindowProc(HWND,UINT,WPARAM,LPARAM);
- extern LRESULT CALLBACK _GViewWindowProc(HWND,UINT,WPARAM,LPARAM);
-
- extern HWND _GMainWindow; /* main window here */
- extern HWND _GMDIWindow; /* non-NULL == MDI */
-
- extern XGWindow *_GWindow;
- extern XGView *_GView;
-
-
- #endif
-
- #if OPT_MACOS == 1
-
- extern EventRecord _GCurEvent;
-
- #endif
-
-
- #if defined(__MWERKS__)
- #if defined(macintosh)
- #pragma options align=reset
- #endif
- #if defined(__INTEL__)
- #pragma pack(pop)
- #endif
- #endif
-
-
- #endif /* __XAPPLICATION_H__ */
-